'use strict';

const conn = require('../../../libs/Conn');
const moment = require('moment');

module.exports = async function (params) {
    let statusSql = ``;
    if(params.type === '2'){
        statusSql = `UPDATE engineering_progress_file SET completion_initial_inspection = 3 WHERE engineering_id = '${params.engineering_id}'`
    }else{
        let rec = await conn(`SELECT create_time,update_time FROM engineering_progress_completion WHERE engineering_id = '${params.engineering_id}';`);
        if(moment(rec[0].create_time).format() === moment(rec[0].update_time).format()){
            statusSql = `UPDATE engineering_progress_file SET completion_initial_inspection = 2 WHERE engineering_id = '${params.engineering_id}'`
        }
    }
    let obj = {
        party_a_material:params.party_a_material,
        construction_material:params.construction_material,
        acceptance_data:params.acceptance_data,
    };
    let sql = `UPDATE engineering_progress_completion  SET ? WHERE engineering_id = ?;`+statusSql;
    await conn(sql,[obj,params.engineering_id]);
    return {success:true}
};